package com.mark.search;

import com.alibaba.fastjson.JSON;
import com.mark.search.config.Const;
import com.mark.search.config.ElasticSearchOperation;
import com.mark.search.config.EsConfig;
import com.mark.search.dto.EsDTO;
import com.mark.search.dto.QueryParam;
import com.mark.search.dto.RespVO;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 * 单元测试
 * </p>
 *
 * @author : mark
 * @since : 2022/7/19 15:16
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ElasticsearchExampleApplication.class, properties = {
        "spring.profiles.active=dev"
})
@Slf4j
public class EsDev {

    @Resource
    ElasticSearchOperation searchOperation;

    @Resource
    EsConfig esConfig;

    @Test
    public void testAdd() {
        EsDTO esDTO = new EsDTO();
        String startTime = Const.DT_FORMATTER.format(LocalDateTime.now());
        String endTime = Const.DT_FORMATTER.format(LocalDateTime.now());
        esDTO.setStartTime(startTime);
        esDTO.setEndTime(endTime);
        esDTO.setStatus(Const.STATUS_1);
        esDTO.setDesc("描述信息。。。");
        esDTO.setName("tom");
        String s1 = String.valueOf(System.currentTimeMillis());
        esDTO.setId(s1);
        searchOperation.add(esConfig.getIndexName1(), esDTO, s1);
    }

    @Test
    public void testQuery() {
        QueryParam param = new QueryParam();
        RespVO respVO = searchOperation.queryOrders(param);
        log.info("查询结果：{}", JSON.toJSONString(respVO));
    }

}
